/*
 * @Description: 表单数据存储-step1
 * @Author: ziwei.ma
 * @Date: 2019-08-02 16:01:50
 * @Last Modified by: ziwei.ma
 * @Last Modified time: 2019-08-23 23:32:29
 */
const state = {
  numberOfPeople: 1,
  numberOfVehicles: 1,
  startPoint: {},
  endPoint: {},
  stationList: [],
  startTime: {},
  endTime: {}
}

const getters = {
  numberOfPeople: state => state.numberOfPeople,
  numberOfVehicles: state => state.numberOfVehicles,
  startPoint: state => state.startPoint,
  endPoint: state => state.endPoint,
  stationList: state => state.stationList,
  startTime: state => state.startTime,
  endTime: state => state.endTime
}

const actions = {
  fetchNumberOfPeople: ({ commit, state }, text) => {
    commit('updateNumberOfPeople', text)
  },
  fetchNumberOfVehicles: ({ commit, state }, text) => {
    commit('updateNumberOfVehicles', text)
  },
  fetchStartPoint: ({ commit, state }, text) => {
    commit('updateStartPoint', text)
  },
  fetchEndPoint: ({ commit, state }, text) => {
    commit('updateEndPoint', text)
  },
  AddStationList: ({ commit, state }, obj) => {
    commit('updateAddStationList', obj)
  },
  StationAssignment: ({ commit, state }, arr) => {
    commit('updateStationAssignment', arr)
  },
  fetchStartTime: ({ commit, state }, text) => {
    commit('updateStartTime', text)
  },
  fetchEndTime: ({ commit, state }, text) => {
    commit('updateEndTime', text)
  }
}

const mutations = {
  updateNumberOfPeople: (state, numberOfPeople) => {
    state.numberOfPeople = numberOfPeople
  },
  updateNumberOfVehicles: (state, numberOfVehicles) => {
    state.numberOfVehicles = numberOfVehicles
  },
  updateStartPoint: (state, startPoint) => {
    state.startPoint = startPoint
  },
  updateEndPoint: (state, endPoint) => {
    state.endPoint = endPoint
  },
  updateAddStationList: (state, stationList) => {
    state.stationList.push(stationList)
  },
  updateStationAssignment: (state, arr) => {
    state.stationList = []
    arr.map(item => {
      state.stationList.push(item)
    })
  },
  updateStartTime: (state, startTime) => {
    state.startTime = startTime
  },
  updateEndTime: (state, endTime) => {
    state.endTime = endTime
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
